WEBVTT

00:01.070 --> 00:06.950
In this video we are going to create the equal weighted portfolio consisting of our six portfolio stocks

00:07.520 --> 00:12.770
and equal weighted means that at each timestamp the weight of each single stock in the portfolio is

00:12.770 --> 00:14.770
one divided by six.

00:14.810 --> 00:20.330
So let's first of all import pen us and we also import an umpire and met plot lip and also seaborne

00:20.840 --> 00:22.540
and we define that float object.

00:22.560 --> 00:24.390
So to have uh two decimals.

00:24.410 --> 00:30.190
So let's do this and then we import our portfolio stocks from the portfolio of stocks.

00:30.210 --> 00:37.130
Yes we file and we create a day time index and we save uh the data frame and the value of stocks.

00:37.130 --> 00:38.380
So let's have a look.

00:38.390 --> 00:45.140
So these are the adjusted to close prices over time and actually calculating the return of an equal

00:45.140 --> 00:47.930
weighted portfolio is pretty simple.

00:47.930 --> 00:54.050
So we simply have to calculate the mean return of our six stocks on each timestamp and therefore first

00:54.050 --> 01:01.400
of all we create the returns data frame with the percentage change method and we save the returns data

01:01.400 --> 01:08.110
frame and the variable red so this is the returns data frame as the daily returns.

01:08.110 --> 01:13.770
And as I said to get the daily returns for our equal weighted portfolio we simply have to calculate

01:13.780 --> 01:21.850
here the average are the mean return of the six stocks on each timestamp so to say we have to calculate

01:21.850 --> 01:29.440
the row vice mean and we can do this with the mean method and pass on to the access parameter to get

01:29.530 --> 01:37.960
the mean values per Roe so these are the mean values are the mean returns pair Roe up her timestamp

01:38.890 --> 01:41.030
and with this we are finished here.

01:41.100 --> 01:46.900
That's uh that daily returns of the equal weighted portfolio but as the next step we also want to create

01:46.900 --> 01:53.500
portfolios that are not equal weighted and therefore we have to derive a more general way to get to

01:53.500 --> 01:56.850
the weighted average return on each timestamp.

01:56.950 --> 01:58.840
And uh let's have a look here.

01:58.840 --> 02:05.530
So first of all we need to define the amount of assets or the amount of stocks that should be in our

02:05.530 --> 02:06.460
portfolio.

02:06.700 --> 02:13.990
So in this case we are working with six stocks and we actually can determine the length of our columns

02:14.020 --> 02:15.160
index.

02:15.160 --> 02:22.860
So no surprise we have six and the next step we create a list with the weights of our 6 stocks.

02:22.870 --> 02:30.170
So with the equal weighted portfolio we have six times the weight of fund divided by six.

02:30.190 --> 02:33.550
So we are creating the list weights.

02:33.610 --> 02:36.690
And this is a list comprehension.

02:36.730 --> 02:42.300
So for you and range six or six times we create 1 divided by 6.

02:42.310 --> 02:43.060
So let's have a look.

02:44.780 --> 02:48.790
So you have six times the rate one divided by six.

02:48.860 --> 02:55.040
And now we want to calculate the evaded average return for all time stems and therefore on the first

02:55.040 --> 02:58.730
step we have to multiply the return of each stock.

02:59.180 --> 03:06.800
So here these are the daily returns and we have to multiply them by the respective weights here and

03:06.860 --> 03:09.080
uh we have to do this for each timestamp.

03:09.470 --> 03:16.940
And finally we have to sum up then the weighted daily returns to get uh the weighted average return

03:16.940 --> 03:18.540
for the six stocks.

03:18.860 --> 03:26.030
And uh we can do this year and two steps are first of all we have our returns data frame and we multiply

03:26.030 --> 03:33.770
the returns data frame with the weights list and we pass columns to the access parameter because we

03:33.770 --> 03:38.400
want to apply here the respective weights on our columns.

03:38.510 --> 03:44.150
So here the first weight should always be applied on the Amazon stock for example.

03:44.630 --> 03:46.770
So let's do this here.

03:49.090 --> 03:54.030
So these are the evaded daily returns and to get the weighted average.

03:54.060 --> 04:01.230
We have to take the sum so we use the same method and pass one to the access parameter to uh some of

04:01.270 --> 04:04.060
the data frame upper row wise or per row.

04:05.950 --> 04:10.850
And again here we have for the daily returns for our equal weighted portfolio.

04:11.020 --> 04:13.890
And as you can see here we change here two methods.

04:13.990 --> 04:21.970
So the model method and the sum method and we can actually combine these two steps into one step by

04:21.970 --> 04:30.130
using the dot product on a matrix multiplication and we can do this with the top method.

04:30.580 --> 04:38.300
So we take our returns data frame and we apply a matrix multiplication with the top method and we pass

04:38.450 --> 04:40.710
our weights the list.

04:40.720 --> 04:43.120
So this gives us actually the same result.

04:43.990 --> 04:48.520
So here we have the daily returns of the equal weighted portfolio.

04:48.640 --> 04:55.450
And finally we create a new column equal weighted portfolio for our returns data frame by using exactly

04:55.720 --> 04:59.190
the code so let's do this and let's have a look.

05:00.350 --> 05:07.280
So here we have the six constituents of our portfolio and the equal weighted portfolio and for all of

05:07.280 --> 05:10.430
them we feel that daily returns on each timestamp.

05:10.660 --> 05:14.990
And now as a next step we want to aggregate here the daily returns.

05:14.990 --> 05:22.520
And we want to calculate the annualized mean return and the annualized standard deviation of returns.

05:22.520 --> 05:26.390
And therefore we create here the summary data frame.

05:26.450 --> 05:33.560
So first of all we calculate the mean return of our daily returns and the standard deviation of daily

05:33.560 --> 05:34.800
returns.

05:35.000 --> 05:36.710
And we use here the ACT method.

05:36.740 --> 05:39.860
So let's do this and let's have a look.

05:39.860 --> 05:47.510
So we actually transposed the data frame in order to FESA the index our stocks and our portfolio and

05:47.510 --> 05:48.560
as columns.

05:48.710 --> 05:53.010
The mean return and the standard deviation of returns.

05:53.420 --> 06:02.740
And then it's definitely a good idea to rename the column labels to return and risk and still we have

06:02.750 --> 06:06.030
yeah the mean and the standard deviation of daily returns.

06:06.320 --> 06:15.850
And uh it's more intuitive to analyze them so we multiply the mean return with 252.

06:15.860 --> 06:19.020
So that's the average amount of trading days.

06:19.250 --> 06:24.320
And we multiply the risk by the square root of 252.

06:24.350 --> 06:25.810
So this is nothing new.

06:26.970 --> 06:34.860
And finally we feel our summary data frame with the annualized return and the annualized risk.

06:34.860 --> 06:37.700
And finally we can also create a scatter plot.

06:37.860 --> 06:46.050
So we use the plot method on our summary data frame and on the x axis we have the risk column and on

06:46.050 --> 06:48.420
the y axis the return column.

06:49.050 --> 06:54.460
So we actually should get the seven dots seven points here and our scatter plot.

06:54.570 --> 06:58.770
And we also annotate the label for each point for each dot here.

06:58.770 --> 07:02.760
So that's the take us and the equal weighted portfolio.

07:03.330 --> 07:04.520
And let's have a look here.

07:06.890 --> 07:13.600
So here we have the total risk return profile for our six stocks and for our equal weighted portfolio.

07:14.300 --> 07:16.370
So this is also nothing new here.

07:16.370 --> 07:21.880
So here we have our equal weighted portfolio and these are our six constituents.

07:22.160 --> 07:29.840
And finally to save some time and some code in our next videos we define a function annualized the risk

07:29.870 --> 07:33.950
and return where we pass a return data frame.

07:33.950 --> 07:43.630
So for example here this is our returns data frame and we pass the return data frame to the function

07:44.590 --> 07:51.520
and actually the function calculates the mean and the standard deviation and it renames the columns

07:51.550 --> 07:54.190
and annualize this risk and return.

07:54.190 --> 07:59.140
And then finally returns the final summary data frame.

07:59.410 --> 08:04.340
So we are defining the function here for the next videos to save some code and some time.

08:04.580 --> 08:10.750
And uh with uh this we are finishing with this video and I hope to see you also in the next one by.
